//Shop implementation

#include "checkout.h"
#include <iostream>
using namespace std;

checkout::checkout(){
                     //Nothing here
}

checkout::checkout(sync *sync_object, shop *shop_object){
                        sync_obj = sync_object;
                        shop_obj = shop_object;
}

void checkout::start_checkout(){
     while(((*shop_obj).peek()).getActionTime() == (*sync_obj).return_time()){
                                                cout << "Checkout Started." << endl;
                                                      Time time_conv;
                                                      Customer_Obj temp_customer = (*shop_obj).go2checkout();
                                                      temp_customer.setLineProcessTime(time_conv.round2minutes(temp_customer.getNumItems() * 3) + (*sync_obj).return_time());
                                                      if(temp_customer.getPayType() == "Credit" && temp_customer.getNumItems() <= 10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 30 + (*sync_obj).return_time());
                                                                                    quick.enqueue(temp_customer);
                                                      }
                                                      if(temp_customer.getPayType() == "Credit" && temp_customer.getNumItems() >10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 30 + (*sync_obj).return_time());
                                                                                    regular.enqueue(temp_customer);
                                                      }
                                                      if(temp_customer.getPayType() == "Check" && temp_customer.getNumItems() <= 10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 75 + (*sync_obj).return_time());
                                                                                    quick.enqueue(temp_customer);
                                                      }
                                                      if(temp_customer.getPayType() == "Check" && temp_customer.getNumItems() >10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 75 + (*sync_obj).return_time());
                                                                                    regular.enqueue(temp_customer);
                                                      }
                                                      if(temp_customer.getPayType() == "Cash" && temp_customer.getNumItems() <= 10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 10 + (*sync_obj).return_time());
                                                                                    cash_quick.enqueue(temp_customer);
                                                      }
                                                      if(temp_customer.getPayType() == "Cash" && temp_customer.getNumItems() >10){
                                                                                    temp_customer.setActionTime(temp_customer.getLineProcessTime() + 10 + (*sync_obj).return_time());
                                                                                    cash.enqueue(temp_customer);
                                                      }
     }
}

void checkout::exit_store(){
             if((quick.peek()).getActionTime() == (*sync_obj).return_time())
                                           quick_c = quick.dequeue();
             if((regular.peek()).getActionTime() == (*sync_obj).return_time())
                                           regular_c = regular.dequeue();
             if((cash.peek()).getActionTime() == (*sync_obj).return_time())
                                           cash_c = cash.dequeue();
             if((cash_quick.peek()).getActionTime() == (*sync_obj).return_time())
                                           cash_quick_c = cash_quick.dequeue();
}

Customer_Obj checkout::peek(){
             if((quick.peek()).getActionTime() == (*sync_obj).return_time())
                                           return(quick.peek());
             if((regular.peek()).getActionTime() == (*sync_obj).return_time())
                                           return(regular.peek());
             if((cash.peek()).getActionTime() == (*sync_obj).return_time())
                                           return(cash.peek());
             if((cash_quick.peek()).getActionTime() == (*sync_obj).return_time())
                                           return(cash_quick.peek());
}

void checkout::show_stats(){
     Time maxWaitQuick(quick.getMaxWait());
     Time maxWaitRegular(regular.getMaxWait());
     Time maxWaitCash(cash.getMaxWait());
     Time maxWaitCashQuick(cash_quick.getMaxWait());
     Time avgWaitQuick(quick.getAvgWait());
     Time avgWaitRegular(regular.getAvgWait());
     Time avgWaitCash(cash.getAvgWait());
     Time avgWaitCashQuick(cash_quick.getAvgWait());
     cout << "--Checkout--" << endl;
     cout << quick.getNumProcessed() + regular.getNumProcessed() + cash.getNumProcessed() + cash_quick.getNumProcessed()<< " Customers Processed" << endl;
     cout << "Maximum Size of Regular Express Line: " << quick.getMaxSize() << endl;
     cout << "Maximum Regular Express Wait Time: "; maxWaitQuick.dispTime(); cout << endl;
     cout << "Average Regular Express Wait Time: "; avgWaitQuick.dispTime(); cout << endl;
     cout << "Maximum Size of Cash Only Express Line: " << cash_quick.getMaxSize() << endl;
     cout << "Maximum Cash Only Express Wait Time: "; maxWaitCashQuick.dispTime(); cout << endl;
     cout << "Average Cash Only Express Wait Time: "; avgWaitCashQuick.dispTime(); cout << endl;
     cout << "Maximum Size of Cash Only Line: " << cash.getMaxSize() << endl;
     cout << "Maximum Cash Only Wait Time: "; maxWaitCash.dispTime(); cout << endl;
     cout << "Average Cash Only Wait Time: "; avgWaitCash.dispTime(); cout << endl;
     cout << "Maximum Size of Regular Line: " << regular.getMaxSize() << endl;
     cout << "Maximum Regular Wait Time: "; maxWaitRegular.dispTime(); cout << endl;
     cout << "Average Regular Wait Time: "; avgWaitRegular.dispTime(); cout << endl;
}
